<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <title>修改问题</title>
    <link rel="stylesheet" href="../css/index.css" />
    <link rel="stylesheet" href="../css/font-icons.css" />
    <link rel="stylesheet" href="../css/mobiscroll.css">

</head>
<body>
<div id="change">
    <input type="text" name="pk_support" style="display:none" />
    <ul class="list">
        <li>
            <span class="title_A">大区:</span>
            <select name="areaname">
                <option value="北京">北京</option>
                <option value="上海">上海</option>
                <option value="深圳">深圳</option>
                <option value="浙江区">浙江区</option>
                <option value="苏皖区">苏皖区</option>
                <option value="华南区">华南区</option>
                <option value="福建区">福建区</option>
                <option value="中南区">中南区</option>
                <option value="西南区">西南区</option>
                <option value="西北区">西北区</option>
                <option value="津冀区">津冀区</option>
                <option value="东北区">东北区</option>
                <option value="山东区">山东区</option>
                <option value="央本-军工">央本-军工</option>
            </select>
        </li>
        <li>
            <span class="title_A">项目名称:</span>
            <select name="projectname">

            </select>
        </li>
        <li>
            <span class="title_A">领域:</span>
            <select name="field">
                <option value="财务会计">财务会计</option>
                <option value="增值税管理平台">增值税管理平台</option>
                <option value="报表">报表</option>
                <option value="合并报表">合并报表</option>
                <option value="电子采购">电子采购</option>
                <option value="产品成本">产品成本</option>
                <option value="资金管理">资金管理</option>
                <option value="资产管理">资产管理</option>
                <option value="人力资本">人力资本</option>
                <option value="全面预算">全面预算</option>
                <option value="供应链">供应链</option>
                <option value="利润中心会计">利润中心会计</option>
                <option value="进出口">进出口</option>
                <option value="应用平台">应用平台</option>
                <option value="CRM">CRM</option>
                <option value="财务共享">财务共享</option>
                <option value="电子销售">电子销售</option>
                <option value="全渠道营销">全渠道营销</option>
                <option value="医药">医药</option>
                <option value="HR">HR</option>
                <option value="ECM">ECM</option>
                <option value="生产制造">生产制造</option>
                <option value="交通公用">交通公用</option>
                <option value="NC升迁">NC升迁</option>
            </select>
        </li>
        <li>
            <span class="title_A">录单人:</span>
            <span class="text"></span>
            <input type="text" value="" name="creatorname" style="display:none">
        </li>
        <li>
            <span class="title_A">解决人:</span>
            <input placeholder="邮箱前缀" type="text" name="solvername">
            <span class="solvepeople"></span>
        </li>
        <li>
            <span class="title_A">修改人:</span>
            <span class="text"></span>
            <input type="text" name="modifier" style="display:none">
            <input type="text" name="modifiername" style="display:none">
        </li>
        <li>
            <span class="title_A name"></span>
            <textarea name="supportname" placeholder="最多20字"></textarea>
        </li>
        <li>
            <span class="title_A describe"></span>
            <textarea name="description" placeholder="最多400字" class="descript" rows="6"></textarea>
        </li>
        <li>
            <span class="title_A">计划用时:</span>
            <input type="number" min="1" max="99" name="plantime">
            <span class="time"></span>
        </li>
        <li>
            <span class="title_A">计划完成时间:</span>
            <input type="text" name="finishtime" id="finishtime">
            <span class="dateDelete">×</span>
        </li>
        <li>
            <span class="title_A">实际用时:</span>
            <input type="number" min="1" max="99" name="actualtime">
            <span class="time"></span>
        </li>
        <li>
            <span class="title_A">加班用时:</span>
            <input type="number" min="1" max="99" name="overtime">
            <span class="time">小时</span>
        </li>
        <li>
            <span class="button">提交</span>
        </li>
    </ul>
</div>
<div id="footer">
    <ul>
        <li>
            <a href="../index.html">
                <div>首页</div>
            </a>
        </li>
        <li>
            <a href="add.html">
                <div>添加</div>
            </a>
        </li>
        <li>
            <a href="caculate.html">
                <div>统计</div>
            </a>
        </li>
        <li class="active">
            <a href="mine.html">
                <div>我的</div>
            </a>
        </li>
    </ul>
</div>
<script src="../js/jquery-1.7.2.min.js"></script>
<script src="../js/mobiscroll.js"></script>
<script src="../js/jquery.placeholder.js"></script>
<script>
    $(function(){
        $('input, textarea').placeholder({customClass:'my-placeholder'});
        $("textarea[name='description']").bind('blur',function(){
            var length = $(this).val().length;
            if(length>100){
                alert('最多输入400字')
            }
        }) ;
        $("textarea[name='supportname']").bind('blur',function(){
            var length = $(this).val().length;
            if(length>20){
                alert('最多输入20字') ;
                return false
            }
        }) ;



        if(localStorage.token == 'undefined'){
            alert('请先登录') ;
            window.location.href = 'login.html'
        }
        $('.enter').click(function(){
            localStorage.token = '';
            localStorage.userid = '';
            window.location.href = 'login.html'
        }) ;
        $('.dateDelete').click(function(){
            $('#finishtime').val('')
        });
        //获取问题id
        var pk_support=window.location.search.split("pk_support=")[1];
        $("input[name='pk_support']").val(pk_support);

            var name=localStorage.userName ;
            $("input[name='modifier']").val(localStorage .token).prev(".text").html(name);
            $("input[name='modifiername']").val(name);


        var params={
            beginindex:1,
            endindex:1,
            param:JSON.stringify({pk_support:pk_support})
        };
        $.post(localStorage.location+"alldhsupports",params,function(data){

            var data=data.data[0];
            switch(data.supporttype){
                case "bug":
                    $("[name='supportname']").prev("span").html("BUG名称");
                    $("textarea[name='description']").prev("span").html("BUG描述");
                    $("input[name='plantime']").next("span").html("小时");
                    $("input[name='actualtime']").next("span").html("小时");
                    break;
                case "demand":
                    $("[name='supportname']").prev("span").html("需求名称");
                    $("textarea[name='description']").prev("span").html("需求描述");
                    $("input[name='plantime']").next("span").html("人/天");
                    $("input[name='actualtime']").next("span").html("人/天");
                    break;
            }
            if(data.solvername){
                $("input[name='solvername']").val(data.solvername);
            }
            if(data.supportname){
                $("[name='supportname']").val(data.supportname);
            }
            if(data.description){
                $("textarea[name='description']").html(data.description);
            }
            if(data.plantime){
                $("input[name='plantime']").val(data.plantime);
            }
            if(data.finishtime){
                $("input[name='finishtime']").val(data.finishtime);
            }
            if(data.actualtime){
                $("input[name='actualtime']").val(data.actualtime);
            }
            if(data.areaname){
                $("select[name='areaname']").val(data.areaname);
            }
            if(data.projectname){
                $("select[name='projectname']").val(data.projectname);
            }
            if(data.field){
                $("select[name='field']").val(data.field);
            }
            if(data.creatorname){
                $("input[name='creatorname']").val(name).prev(".text").html(data.creatorname);
            }
            if( $("input[name='solvername']").val()){
                $('.solvepeople').html(data.namemobile)
            }

            if(data.overtime){
                $("input[name='overtime']").val(data.overtime);
            }
            $.post(localStorage.location+"getdhprojectname",{areaname:$("[name='areaname']").val()},function(data){
                $("[name='projectname']").html("");
                var data=data.data;
                if(!data.length){
                    $("[name='projectname']").append("<option value='无'>此大区无项目</option>");
                }else{
                    for(var i=0;i<data.length;i++){
                        $("[name='projectname']").append("<option value='"+data[i]+"'>"+data[i]+"</option>");
                    }
                }
            });
            $("[name='projectname'] option[value = "+ data.projectname +"]").attr('selected',true);
            var imgSrc = [];
            var imgBig = [];
            $(".img-box").each(function(){
                imgBig.push($(this).find("input").val());
                imgSrc.push($(this).find("img").attr("src"));
            });
            localStorage .imgBig=imgBig;
            $(".img-box").off("click")
            $(".img-box").on("click",function(){
                if(confirm("要删除这张图片吗？")){
                    var index=$(this).index();
                    for(var i=index;i<imgBig.length-1;i++){
                        imgBig[i]=imgBig[i+1];
                        imgSrc[i]=imgSrc[i+1];
                    }
                    imgBig.pop();
                    imgSrc.pop();
                    if(imgBig.length==2){
                        $('.upload').css('display','inline-block');
                    }
                    $(this).remove();
                    localStorage .imgBig=imgBig;
                }
            });

        });
        //实时输入查询人员信息================
        $("input[name='solvername']").bind("input propertychange",function () {
            var solvername = $(this).val();
            var that = this;
            if ($(this).val() != "") {
                $.post(localStorage.location+"getdhusernameandmobile", {solvername: solvername}, function (data) {
                    console.log(data)
                    if (!data.data) {
                        $('.solvepeople').html('查无此人')
                    }else{
                        $('.solvepeople').html(data.data)
                    }

                })
            }else{
                $(that).val('')  ;
                $('.solvepeople').html('')
            }
        });
        setTimeout(function(){
            $.post(localStorage.location+"getdhusernameandmobile", {solvername: $("input[name='solvername']").val()}, function (data) {
                console.log(data)
                if (!data.data) {
                    $('.solvepeople').html('查无此人')
                }else{
                    $('.solvepeople').html(data.data)
                }

            }) ;
        },500)

    });

    $(function(){
        //大区绑定各自的项目 =========================================
        $("[name='areaname']").change(function(){
            $.post(localStorage.location+"getdhprojectname",{areaname:$("[name='areaname']").val()},function(data){
                $("[name='projectname']").html("");
                var data=data.data;
                if(!data.length){
                    $("[name='projectname']").append("<option value='无'>此大区无项目</option>");
                }else{
                    for(var i=0;i<data.length;i++){
                        $("[name='projectname']").append("<option value='"+data[i]+"'>"+data[i]+"</option>");
                    }
                }
            });
        }) ;
        $(".button").on("click",function(){
            var imgBig=(localStorage .imgBig).split(",");
            if (!$("[name='supportname']").val()) {
                alert("问题名称不能为空！");
                return false;
            }
            if ($("[name='description']").val() == '') {
                alert("问题描述不能为空！");
                return false;
            }
            if($("textarea[name='supportname']").val().length > 20){
                alert('BUG名称最多20字');
                return false;
            }
            if($("textarea[name='description']").val().length > 400){
                alert('BUG描述最多400字');
                return false;
            }
            if ($("[name='projectname']").val() == '无') {
                alert("此大区没有项目，不能提交！");
                return false;
            }
            if($("[name='solvername']").val()!='' && $('.solvepeople').html() == '查无此人'){
                alert('请输入正确的解决人') ;
                return false
            }
            var arr = /^\+?[1-9][0-9]?(\.5)?$/;
            var arrr=/^(0\.5)$/;
            var text1 = $("input[name='plantime']").val();
            var text2 = $("input[name='actualtime']").val();
            var text3 = $("input[name='overtime']").val();

            if(!arr.test(text1) && !arrr.test(text1)){
                alert("计划用时：请输入0.5 , 1 , 1.5 …… 99.5!",{icon:7,closeBtn: 0});
                return 0;
            }
            if(text2){
                if(!arr.test(text2) && !arrr.test(text2)){
                    alert("实际用时：请输入0.5 , 1 , 1.5 …… 99.5!",{icon:7,closeBtn: 0});
                    return 0;
                }
            }
            if(text3){
                if(!arr.test(text3) && !arrr.test(text3)){
                    alert("加班用时：请输入0.5 , 1 , 1.5 …… 99.5!",{icon:7,closeBtn: 0});
                    return 0;
                }
            }
            var params={
                pk_support:$("[name='pk_support']").val(),
                areaname:$("[name='areaname']").val(),
                projectname:$("[name='projectname']").val(),
                field:$("[name='field']").val(),
                creatorname:$("[name='creatorname']").val(),
                solvername:$("[name='solvername']").val(),
                supportname:$("[name='supportname']").val(),
                description:$("[name='description']").val(),
                plantime:$("[name='plantime']").val(),
                finishtime:$("[name='finishtime']").val(),
                actualtime:$("[name='actualtime']").val(),
                modifier:$("[name='modifier']").val(),
                modifiername:$("[name='modifiername']").val(),
                overtime:$("[name='overtime']").val(),
                namemobile: $(".solvepeople").html(),
                image1:imgBig[0],
                image2:imgBig[1],
                image3:imgBig[2]
            };


                $.post(localStorage.location+"editdhsupport",params,function(data){
                    if(data.status=='success'){
                        alert("修改成功！");
                        window.location.href="mine.html";
                    }
                });


        });

    });
    $(function(){
        var opt_date = {
            preset: 'date', //日期date
            theme: 'default', //皮肤样式
            dateFormat: 'yy-mm-dd', // 日期格式
            setText: '确定', //确认按钮名称
            cancelText: '取消', //取消按钮
            dateOrder: 'yymmdd', //面板中日期排列格式
            dayText: '日', monthText: '月', yearText: '年', //面板中年月日文字
        };
        $('#finishtime').mobiscroll(opt_date)
    });


</script>
</body>
</html>